﻿/*
* ////////////////////////////////////////////////
*
* 开发者：AZPEP
* 友情链接：
*	-	B站：		零分的考卷			https://space.bilibili.com/257391258
*	-	Github：	AZPEP-BiliBili		https://github.com/AZPEP-BiliBili
*	-	Gitee：		AZPEP_BiliBili		https://gitee.com/AZPEP_BiliBili
*
* CopyRight AZPEP
*
* ////////////////////////////////////////////////
*/
#include "pch.h"
#include <chrono>
#include <sstream>
#include <locale>
#include <codecvt>
#include "GetStr.h"

#include <comutil.h>
#pragma comment(lib, "comsuppw.lib")
#include <iomanip>

//获取当前时间
std::wstring LogGetDateString() {
	auto time = std::chrono::system_clock::now();
	auto t = std::chrono::system_clock::to_time_t(time);

	std::stringstream sss;
	sss << std::put_time(std::localtime(&t), "%Y-%m-%d %H:%M:%S");

	std::wstringstream ss;
	ss << sss.str().c_str();

	auto milesec = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch());
	//ss << ":" << milesec_str.substr(0, 4);
	//ss << ":" << MsFillZero_AZPEPBiliBili123456789(milesec.count());
	//ss << ":" << MsFillZero_AZPEPBiliBili123456789((int)floor(milesec.count())).substr(MsFillZero_AZPEPBiliBili123456789((int)floor(milesec.count())).length() - 6, 3);

	auto length = std::to_string(milesec.count()).length();
	std::wstring RealMile = wstr(std::to_string(milesec.count()).substr(length - 6, 4));
	ss << ":" << RealMile;
	return ss.str();
}

std::wstring LogGetDateStringChinese() {
	auto tt = std::chrono::system_clock::now();
	auto t = std::chrono::system_clock::to_time_t(tt);
	time_t time_seconds = time(0);

	std::stringstream sss;
	sss << std::put_time(localtime(&t), "%Y年%m月%d日 %H:%M:%S");
	std::wstringstream ss;
	ss << sss.str().c_str();
	auto milesec = std::chrono::duration_cast<std::chrono::microseconds>(tt.time_since_epoch());
	//ss << ":" << MsFillZero_AZPEPBiliBili123456789((int)floor(milesec.count())).substr(MsFillZero_AZPEPBiliBili123456789((int)floor(milesec.count())).length() - 6, 3);

	auto length = std::to_string(milesec.count()).length();
	std::wstring RealMile = wstr(std::to_string(milesec.count()).substr(length - 6, 4));
	ss << ":" << RealMile;

	return ss.str();
}

std::wstring LogGetDateStringPath() {
	auto time = std::chrono::system_clock::now();
	auto t = std::chrono::system_clock::to_time_t(time);

	std::stringstream sss;
	sss << std::put_time(localtime(&t), "%Y-%m-%d_%H-%M-%S");
	std::wstringstream ss;
	ss << sss.str().c_str();

	auto milesec = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch());
	//ss << "-" << milesec_str.substr(0, 4);
	//ss << "-" << MsFillZero_AZPEPBiliBili123456789((int)floor(milesec.count())).substr(MsFillZero_AZPEPBiliBili123456789((int)floor(milesec.count())).length() - 6, 3);

	auto length = std::to_string(milesec.count()).length();
	std::wstring RealMile = wstr(std::to_string(milesec.count()).substr(length - 6, 4));
	ss << "-" << RealMile;
	return ss.str();
}

std::wstring Double_2f(double num) {
	char c[40];

	sprintf_s(c, 40, "%.2f", num);

	std::wstringstream ss;
	ss << c;

	return ss.str();
}

// convert string to wstring
inline std::wstring to_wide_string(const std::string& input)
{
	_bstr_t t = input.c_str();
	wchar_t* pwchar = (wchar_t*)t;
	std::wstring result = pwchar;
	return result;
}